<style>
<!--
	.grid-view{padding-top:0px;}
-->
</style>
<?php
$this->breadcrumbs=array(
	'Deals'=>array('admin'),
	$model->referenceNo,
);

$this->menu=array(
	array('label'=>'Attachments('.$model->attachmentCount.')','url'=>array('attachment/admin','dealId'=>$model->id)),
	array('label'=>'Add Deal', 'url'=>array('create')),
	array('label'=>'Update Deal', 'url'=>array('update', 'id'=>$model->id)),
	array('label'=>'Delete Deal', 'url'=>'#', 'linkOptions'=>array('submit'=>array('delete','id'=>$model->id),
		'confirm'=>'Are you sure you want to delete this deal? All related records and files will be deleted!')),
	array('label'=>'Manage Deal', 'url'=>array('admin')),
);
?>

<h1>View Deal  <?php echo $model->referenceNo; ?></h1>

<?php $this->widget('zii.widgets.CDetailView', array(
	'data'=>$model,
	'attributes'=>array(
		'referenceNo',
		'bank',
		'teamId',
		array(
			'label'=>'Create User',
			'value'=>$model->createUser?$model->createUser->fullName:'',
		),
	),
)); ?>
<p></p>

<!-- Customer List  -->
 <div class="view-deal-customers">
<h3> Customers: </h3>
<div class="span-13">
<?php 
	$this->widget('zii.widgets.jui.CJuiAutoComplete', array(
			'name'=>'new-deal-customer',
	    	'sourceUrl'=>Yii::app()->controller->createUrl('customer/quickSearch'),
			// additional javascript options for the autocomplete plugin
	      	'options'=>array(
	        	'minLength'=>'2',
				'select'=> 'js:function(event,ui) {
					$("#new-deal-customer-id").val(ui.item.id);
	  			}',
			),
	      	'htmlOptions'=>array(
	        	'style'=>'width:130px;'
	        ),
	        ));
	echo CHtml::hiddenField('new-deal-customer-id','',array('id'=>'new-deal-customer-id'))
?>
<?php
	echo CHtml::button('Add New Customer',array(
			'onclick'=>'
          		var customerId=$("#new-deal-customer-id").val();
          		if(customerId){
		  			$.post("'.Yii::app()->controller->createUrl('dealCustomer/create').'",
		  				{
		  					"DealCustomer[dealId]":"'.$model->id.'",
	 	  					"DealCustomer[customerId]":customerId
		  				},
						function(){window.location.reload();})
				};
		 		return false;'
         ));
?>
</div>

<div class="right">
	<?php echo CHtml::link('Create New Customer', array('customer/create'), array('target'=>'_blank'))?>
</div>
<div class="clear"></div>
<?php
$this->widget('zii.widgets.grid.CGridView', array(
	'id'=>'customer-grid',
	'dataProvider'=>new CArrayDataProvider($model->dealCustomers),
	//'filter'=>$model,
	'columns'=>array(
		array(
			'header'=>'First Name',
			'value'=>'$data->customer->firstName',
		),
		array(
			'header'=>'Last Name',
			'value'=>'$data->customer->lastName',
		),
		array(
			'header'=>'Gender',
			'value'=>'$data->customer->gender?"Male":"Female"',
		),
		array(
			'header'=>'Consultant',
			'value'=>'$data->customer->consultant',
		),
		array(
			'header'=>'Company Name',
			'value'=>'$data->customer->companyName',
		),
		array(
			'header'=>'Phone',
			'value'=>'$data->customer->contactPhone'
		),
		array(
			'header'=>'Mobile',
			'value'=>'$data->customer->contactMobile'
		),
		
		array(
			'class'=>'CButtonColumn',
			'template'=>'{view}{delete}',
			'viewButtonOptions'=>array('target'=>'_blank'),
			'viewButtonUrl'=>'Yii::app()->controller->createUrl("customer/view",array("id"=>$data->customer->id))',
			'deleteButtonUrl'=>'Yii::app()->controller->createUrl("dealCustomer/delete",array("id"=>$data->primaryKey))',
			'deleteConfirmation'=>'Are you sure you want to remove this cutomer from the deal?',
		)
	),
)); 
?>
</div>
<!-- End of Customer List -->



<!-- Loan List -->

<h3>Loans:</h3>
<?php echo CHtml::link('Add Loan',array('loan/create','dealId'=>$model->id))?>&nbsp;
<?php echo CHtml::link('Assign Loan',array('loan/assignLoan','dealId'=>$model->id))?>

<?php 
$this->widget('zii.widgets.grid.CGridView', array(
	'id'=>'loan-grid',
	'dataProvider'=>new CArrayDataProvider($model->loans),
	'rowCssClassExpression'=>'$data->dischargeDate?"loan-discharged-row":""',
	'columns'=>CMap::mergeArray(
		array(
			'productName:raw:Product Name',
			'honeymoonDate:raw:Honeymoon Date',
			'amount:number:Amount($)',
			'rate:raw:Rate(%)',
			'dischargeDate:raw:Discharge Date',
			'commissionPaid:boolean:Commission Paid',
			array(
				'class'=>'CButtonColumn',
				'viewButtonUrl'=>'Yii::app()->controller->createUrl("loan/view",array("id"=>$data->primaryKey))',
				'updateButtonUrl'=>'Yii::app()->controller->createUrl("loan/update",array("id"=>$data->primaryKey))',
				'deleteButtonUrl'=>'Yii::app()->controller->createUrl("loan/delete",array("id"=>$data->primaryKey))',
				'deleteConfirmation'=>'Are you sure you want to delete this loan?',
			),
		),
		GlobalConfiguration::isManageMode()?array(
			array(
				'name'=>'hidden',
				'type'=>'boolean',
				'filter'=>DataUtil::getOptionYesNo(),
			),
		):array()),
)); 
?>
